package cn.ahaiahaixx.dp.decrate;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.Reader;

/**
 * 修饰器模式(系统标配io标配设计模式)
 * 
 * @author Aiden Pearce
 *
 */
public class Demo {
  public static void main(String[] args) throws Exception {
    Food food = new Rice();
    food = new Meat(food);
    food = new Egg(food);
    System.out.println(food);
    food = new Egg(new Meat(new Onion(new Noodle())));
    System.out.println(food);
    System.out.println("系统io=========================");
    // 主的输入流只能读取type(字节流)
    InputStream is = new FileInputStream("修饰器文本演示.txt");
    // byte[] bytes = new byte[8 * 1024];
    // is.read(bytes);
    // 文本输入流，构造的时候必须传入被修饰的主输入流
    InputStreamReader reader = new InputStreamReader(is);
    // 现在可以完成字符输入流
    // char[] chars = new char[8 * 1024];
    // reader.read(chars);
    // 二次修饰,将char流变成字符串输入流
    BufferedReader br = new BufferedReader(reader);
    String line = br.readLine();
    while (line != null) {
      System.out.println(line);
      line = br.readLine();
    }
    br.close();
    reader.close();
    is.close();
    //输出流的设计模式
    PrintWriter writer=new PrintWriter(new FileOutputStream("demo.datatt"));
    writer.println("dadada");
    writer.println();
    writer.println("阿海");
    writer.close();
    
  }
}
